#ifndef JSERVICE_RUNNER_H
#define JSERVICE_RUNNER_H
#include <Windows.h>
#include <unordered_map>
#include <unordered_set>
#include <list>
class JService;
struct JServiceMsg;
class JServiceRunner {
public:
	JServiceRunner();
	static DWORD WINAPI DoWork(void* args);
	int StartService2(JService* service, void* args);
	void run(int threads);
	void stop();
	void sendServiceMsg(int sourceId, int destId, int cmd, int sessionId, void* data);
	JService* getServiceById(int id);
private:
	JService* dequeueService();	
private:
	std::tr1::unordered_map<int, JService*> m_mapServices;
	std::list<JService*> m_listRunning;
	CRITICAL_SECTION m_criServices;
	std::vector<HANDLE> m_vecEvents;
	std::vector<HANDLE> m_vecThreads;
	std::list<int> m_listSleepingThread;
	int m_currentId;
	HANDLE m_event;
	int m_running;
	int m_count;
	FILE* m_log;
};
#endif
